/*
 * Copyright (c) 2020, 2023, 3044483124@qq.com All rights reserved.
 *
 */
package cn.image;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * <p>Project: JavaStudy - WaterImg2
 * <p>Powered by jiangbo On 2023-01-06
 * 21:27:00
 * <p>Created by IntelliJ IDEA
 *
 * @author jiangbo [3044483124@qq.com]
 * @version 1.0
 * @since 8/17
 */
public class WaterImg2 {
    public static void main(String[] args) {
        String file = "C:\\Users\\30444\\Desktop\\截图\\wang_001.png";
        try {
//读取磁盘上的图像文件
            BufferedImage img = ImageIO.read(new File(file));
//建立画笔
            Graphics2D g = img.createGraphics();
//设置画笔线条 文字 平滑
            g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
                    RenderingHints.VALUE_STROKE_DEFAULT);
//水印文字
            String text = "版权所有 ZhaoJiangBo";
//文字颜色
            Color color = Color.WHITE;
//color = new Color(255,255,255); 白色
            color = new Color(0,0,0,100); //最后100值是透明度，黑色透明
            g.setColor(color);
//控制字体 样式 大小
            Font font = new Font("",Font.BOLD,30);
            g.setFont(font);
//水印文字的坐标位置
            int x = 100;
            int y = 200;
            x = img.getWidth() - 350;
            y = img.getHeight() - 30;
//将字符串写到图像上
            g.drawString(text,x,y);
//输出图像文件
            ImageIO.write(img,"png",new File("wang2.png"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}


